home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 8: LINUX Games / Linux Cubed Series 8 - LINUX Games.iso / games / muds / pennmush.000 / pennmush-1.50-p8-linux.tar / pennmush / timer.c < prev    next >
C/C++ Source or Header  |  1992-08-09  |  2KB  |  84 lines

  1. /* timer.c */
  2.  
  3. /* Subroutines for timed events */
  4. #include "copyright.h"
  5.  
  6. #include <stdio.h>
  7. #include <ctype.h>
  8. #include <fcntl.h>
  9. #include <string.h>
  10. #ifdef XENIX
  11. #include <sys/signal.h>
  12. #else
  13. #include <signal.h>
  14. #endif                /* xenix */
  15.  
  16. #include "config.h"
  17. #include "db.h"
  18. #include "interface.h"
  19. #include "match.h"
  20. #include "externs.h"
  21. static int alarm_triggered = 0;
  22. extern char ccom[BUFFER_LEN];
  23. extern void inactivity_check();
  24. extern void log_check();
  25.  
  26. void alarm_handler()
  27. {
  28.   alarm_triggered = 1;
  29.   signal(SIGALRM, (void *) alarm_handler);
  30. }
  31.  
  32. void init_timer()
  33. {
  34.   signal(SIGALRM, (void *) alarm_handler);
  35.   signal(SIGHUP, (void *) alarm_handler);
  36.   alarm(1);
  37. }
  38.  
  39. void dispatch()
  40. {
  41. /*  void do_garbage(); */
  42.  
  43.   extern void fork_and_dump();
  44.  
  45.   /* this routine can be used to poll from interface.c */
  46.   if (!alarm_triggered)
  47.     return;
  48.   alarm_triggered = 0;
  49.   do_second();
  50.  
  51.   {
  52.     static int ticks = FIXUP_INTERVAL;
  53.     if (!ticks--) {
  54.       ticks = FIXUP_INTERVAL;
  55. #ifdef DESTROY
  56.       /* Free list reconstruction */
  57.       strcpy(ccom, "dbck");
  58.       do_dbck(NOTHING);
  59. #endif                /* DESTROY */
  60. #ifdef IDLE_TIMEOUT
  61.       inactivity_check();
  62. #endif                /* IDLE_TIMEOUT */
  63.     }
  64.   }
  65.  
  66.   /* Database dump routines */
  67.   if (options.dump_counter-- <= 0) {
  68.     options.dump_counter = options.dump_interval;
  69.     strcpy(ccom, "dump");
  70.     fork_and_dump();
  71.   }
  72.  
  73. #ifdef RWHO_SEND
  74.   if (options.rwho_counter-- <= 0) {
  75.     options.rwho_counter = options.rwho_interval;
  76.     strcpy(ccom, "update_rwho");
  77.     rwho_update();
  78.   }
  79. #endif
  80.  
  81.   /* reset alarm */
  82.   alarm(1);
  83. }
  84.